package cn.edu.neusoft.wuguangsheng.flowerimpression.activity;

import android.content.Intent;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.EmptyRecyclerView;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.UserAddressListAdapter;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.UserAddressBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.ListListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.GetUserAddressListModel;

public class UserAddressListActivity extends BaseActivity{
    EmptyRecyclerView useraddresslist_rv;
    ImageView useraddresslist_fh;
    private List<UserAddressBean> items;
    Button useraddresslist_btn;
    private boolean up = false;
    View useraddresslist_ev;
    TextView tv_message;


    @Override
    void initView() {
        setLayout_file(R.layout.activity_user_address_list);
        useraddresslist_fh = (ImageView)findViewById(R.id.useraddresslist_fh);
        useraddresslist_rv = (EmptyRecyclerView)findViewById(R.id.useraddresslist_rv);
        useraddresslist_btn = (Button)findViewById(R.id.useraddresslist_btn);
        useraddresslist_ev = (View)findViewById(R.id.useraddresslist_ev);
        tv_message = (TextView)findViewById(R.id.tv_message);

        GetUserAddressListModel getUserAddressListModel = new GetUserAddressListModel();
        getUserAddressListModel.getUserAddressList(getid(), new ListListener<UserAddressBean>() {
            @Override
            public void onResponse(List<UserAddressBean> list) {
                LinearLayoutManager linearLayoutManager=new LinearLayoutManager(UserAddressListActivity.this);
                linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                useraddresslist_rv.setLayoutManager(linearLayoutManager);
                items=list;
                UserAddressListAdapter userAddressListAdapter=new UserAddressListAdapter(UserAddressListActivity.this,items,R.layout.address_user_item,getid());
                useraddresslist_rv.setAdapter(userAddressListAdapter);
                useraddresslist_rv.setItemAnimator(new DefaultItemAnimator());
                tv_message.setText("收货地址为空，请快去添加你的收货地址吧！");
                useraddresslist_rv.setEmptyView(useraddresslist_ev);
            }

            @Override
            public void onFail(String msg) {

            }
        });





    }

    @Override
    void initEvent() {
        useraddresslist_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(UserAddressListActivity.this,AddAddressressActivity.class);
                startActivity(intent);
            }
        });

        useraddresslist_fh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }

    @Override
    void initDate() {

    }

    @Override
    protected void onPause() {
        super.onPause();
        up = true;

    }

    @Override
    protected void onResume() {
        super.onResume();
        if (up) {
            initView();
            initEvent();
            initDate();
            up = false;
        }
    }


}
